package 二分查找;

public class LeetCode1283_使结果不超过阈值的最小除数 {
    public int smallestDivisor(int[] nums, int threshold) {
        int left = 1;
        int right = 0;
        for(int num:nums){
            right = Math.max(num,right);
        }

        while(left<right){
            int mid = (right-left)/2+left;
            int sum = 0;
            for(int num:nums){
                sum += (num+mid-1)/mid;
            }
            if(sum<=threshold){
                right = mid;
            }else{
                left = mid+1;
            }
        }

        return right;
    }
}
